package
{
	/**
	 * 
	 * @author Polar
	 * @date 2012-12-30
	 * @function 
	 * 
	 */
	
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.display.Stage3D;
	
	import starling.display.BlendMode;
	import starling.display.Image;
	import starling.display.Sprite;
	import starling.events.Event;
	import starling.textures.Texture;
	import starling.textures.TextureSmoothing;
	import starling.utils.deg2rad;
	
	public class Game2 extends Sprite
	{
		private var _imageNum:uint = 200;
		private var _lotsofImages:Vector.<CustomImage> = new Vector.<CustomImage>(_imageNum,true);
		private var container:starling.display.Sprite;
		
		[Embed(source="res/air.png")]
		private static const airImage:Class;
		
		public function Game2()
		{
			super();
			addEventListener(Event.ADDED_TO_STAGE,onAdded);
		}
		private function onAdded(e:Event):void
		{
			container = new starling.display.Sprite;
			container.pivotX = stage.stageWidth>>1;
			container.pivotY = stage.stageHeight>>1;
			container.x = stage.stageWidth>>1;
			container.y = stage.stageHeight>>1;
			addChild(container);
			
			var airBitmap:Bitmap = new airImage;
			
			var texture:Texture = Texture.fromBitmap(airBitmap);
			
			for(var i:int=0;i<_imageNum;++i)
			{
				var image:CustomImage = new CustomImage(texture);
				
				image.alpha = Math.random();
				
				image.x = Math.random()*stage.stageWidth;
				image.y = Math.random()*stage.stageHeight;
				
				image.destX = Math.random()*stage.stageWidth;
				image.destY = Math.random()*stage.stageHeight;
				
				image.scaleX = 0.2;
				image.scaleY = 0.2;
				image.rotation = Math.random()*deg2rad(360);
				
				image.smoothing = TextureSmoothing.BILINEAR;
//				image.color = 0x00ff00;
//				image.blendMode = BlendMode.NORMAL;
				
				container.addChild(image);
				_lotsofImages[i] = image;
				
			}
			container.addEventListener(Event.ENTER_FRAME,onEnterFrame);
			container.flatten();
		}
		private function onEnterFrame(e:Event):void
		{
//			for(var i:int=0;i<_lotsofImages.length;++i)
//			{
//				var image:CustomImage = _lotsofImages[i];
//				
//				image.x -= (image.x - image.destX)*.01;
//				image.y -= (image.y - image.destY)*.01;
//				
//				if(Math.abs(image.x-image.destX)<1 && Math.abs(image.y-image.destY))
//				{
//					image.destX = Math.random()*stage.stageWidth;
//					image.destY = Math.random()*stage.stageHeight;
//					image.rotation = Math.random()*deg2rad(360);
//				}
//			}
			container.rotation += 0.01;
		}
	}
}